/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2007 by Christian Gagne and Marc Parizeau
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1K 7P4
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   Beagle/BitStr/Package.cpp
 *  \brief  Source code of class BitStr::Package.
 *  \author Christian Gagne
 *  $Revision: 1.3 $
 *  $Date: 2007/09/17 17:25:49 $
 */

#include "Beagle/BitStr.hpp"

using namespace Beagle;


/*!
 *  \brief Construct package with bit string objects.
 *  \param inInitSize Size of vectors generated by initialization.
 */
BitStr::Package::Package(unsigned int inInitSize) :
		PackageAbstract("BitStr-Package"),
		mInitSize(inInitSize)
{ }


/*!
 *  \brief Configure system by adding necessary components into it.
 *  \param ioSystem System to configure.
 */
void BitStr::Package::configure(System& ioSystem)
{
	Beagle_StackTraceBeginM();
	Factory& lFactory = ioSystem.getFactory();

	// Add available basic types to the factory
	lFactory.insertAllocator("Beagle::BitStr::BitString", new BitStr::BitString::Alloc);
	lFactory.insertAllocator("Beagle::BitStr::CrossoverOnePointOp", new BitStr::CrossoverOnePointOp::Alloc);
	lFactory.insertAllocator("Beagle::BitStr::CrossoverTwoPointsOp", new BitStr::CrossoverTwoPointsOp::Alloc);
	lFactory.insertAllocator("Beagle::BitStr::CrossoverUniformOp", new BitStr::CrossoverUniformOp::Alloc);
	lFactory.insertAllocator("Beagle::BitStr::InitRampedOp", new BitStr::InitRampedOp::Alloc);
	lFactory.insertAllocator("Beagle::BitStr::InitUniformOp", new BitStr::InitUniformOp::Alloc);
	lFactory.insertAllocator("Beagle::BitStr::MutationFlipBitOp", new BitStr::MutationFlipBitOp::Alloc);
	lFactory.insertAllocator("Beagle::BitStr::Package", new BitStr::Package::Alloc);

	// Aliases to short name of operators
	lFactory.aliasAllocator("Beagle::BitStr::BitString", "BitStr-BitString");
	lFactory.aliasAllocator("Beagle::BitStr::CrossoverOnePointOp", "BitStr-CrossoverOnePointOp");
	lFactory.aliasAllocator("Beagle::BitStr::CrossoverTwoPointsOp", "BitStr-CrossoverTwoPointsOp");
	lFactory.aliasAllocator("Beagle::BitStr::CrossoverUniformOp", "BitStr-CrossoverUniformOp");
	lFactory.aliasAllocator("Beagle::BitStr::InitRampedOp", "BitStr-InitRampedOp");
	lFactory.aliasAllocator("Beagle::BitStr::InitUniformOp", "BitStr-InitUniformOp");
	lFactory.aliasAllocator("Beagle::BitStr::MutationFlipBitOp", "BitStr-MutationFlipBitOp");
	lFactory.aliasAllocator("Beagle::BitStr::Package", "BitStr-Package");

	// Set some basic concept-type associations in factory
	lFactory.setConcept("CrossoverOp", "BitStr-CrossoverUniformOp");
	lFactory.setConcept("Genotype", "BitStr-BitString");
	lFactory.setConcept("InitializationOp", "BitStr-InitUniformOp");
	lFactory.setConcept("MutationOp", "BitStr-MutationFlipBitOp");

	// Set default initialization size
	ioSystem.getRegister().setEntryDefaultValue("bitstr.init.numberbits",
	        new UInt(mInitSize),
	        uint2str(mInitSize));

	Beagle_StackTraceEndM();
}


/*!
 *  \brief List packages which current package depends.
 *  \return Bag with the packages instanciation on which current package depends.
 *
 *  BitStr::Package depends on EC::Package.
 */
PackageAbstract::Bag BitStr::Package::listDependencies()
{
	Beagle_StackTraceBeginM();
	PackageAbstract::Bag lDependencies;
	lDependencies.push_back(new EC::Package());
	return lDependencies;
	Beagle_StackTraceEndM();
}
